// src/stores/article.js
import { defineStore } from "pinia";
import { ref } from "vue";

export const useArticleStore = defineStore("article", () => {
  // 响应式变量
  const article = ref({
    title: '',
    author: '',
    creationTime: '',
    coverImg: '',
    content: '',
    likes: 0,
    collects: 0,
    comments: []
  });

  const setArticle = (newArticle) => {
    article.value = newArticle;
  };

  const updateLikes = (newLikes) => {
    article.value.likes = newLikes;
  };

  const updateCollects = (newCollects) => {
    article.value.collects = newCollects;
  };

  const addComment = (comment) => {
    article.value.comments.push(comment);
  };

  return {
    article,
    setArticle,
    updateLikes,
    updateCollects,
    addComment
  };
}, {
  persist: true // 持久化
});